import uuid
import json

from django.db import models

from common.mixins.app_model_mixin import AppModelMixin
from users.models import User

class UserAuth(AppModelMixin):
    id = models.UUIDField(primary_key=True, max_length=128, default=uuid.uuid1, editable=False, verbose_name="主键id")
    platform = models.CharField(max_length=128, verbose_name="平台", unique=True)
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="用户id")
    is_active = models.BooleanField(default=True, verbose_name="是否开启")
    open_id = models.CharField(max_length=128, verbose_name="平台授权ID", unique=True)
    union_id = models.CharField(max_length=128, verbose_name="平台授权ID")
    content = models.JSONField(max_length=1024, verbose_name="授权信息", null=True)

    class Meta:
        db_table = "user_auth"